﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Itau.IM.Common.Utility;
using Itau.IM.Common.Mainframe.Constants;

namespace Itau.IM.Common.Mainframe.Communication
{
    /// <summary>
    /// Classe responsável pela configuração de transações IMS
    /// </summary>
    public class ImsConfiguration
    {
        #region Propriedades

        public string Computer {get; set; }
        public int Port {get; set; }
        public string Ims { get; set; }
        public string Transaction {get; set; }
        public string User {get; set; }
        public string Password {get; set; }

        #endregion Propriedades

        #region Métodos

        /// <summary>
        /// Construtor
        /// </summary>
        ///
        public ImsConfiguration()
        {

        }

        public ImsConfiguration(string transactionId_)
        {
            string defaultEnvironment = Configuration.GetSetting(ConfigurationConstants.CONFIG_ENVIRONMENT);
            
            try
            {
                this.Computer = Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_COMPUTER, defaultEnvironment));
                this.Port = Convert.ToInt32(Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_PORT, defaultEnvironment)));
                this.Ims = Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_IMS, defaultEnvironment));
                this.Transaction = Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_TRANSACTION, defaultEnvironment, transactionId_));
                this.User = Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_USER, defaultEnvironment));
                this.Password = Configuration.GetSetting(String.Format(ConfigurationConstants.CONFIG_PASSWORD, defaultEnvironment));
            }
            catch (Exception e)
            {
                throw new Exception("Common: Erro ao obter configuração de acesso ao Mainframe", e);
            }
        }

        #endregion Métodos
    }
}